<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="p" uri="/WEB-INF/pages.tld"%>  
<%@taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%
	String webContext = request.getContextPath();
%>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<title>订单同步列表</title>
</head>
<script type="text/javascript"> 
	var msg="${requestScope.tipMessage}";
	if(msg!=""){
	alert(msg);
	}
</script>
<script language="JavaScript"  >
	var req;  
	function createXMLHttpRequest() {   
		if(window.XMLHttpRequest) {  
  		    //IE7, Firefox, Opera支持  
  		    req = new XMLHttpRequest();  
  		}else if(window.ActiveXObject) {  
  		    //IE5,IE6支持  
  		    req = new ActiveXObject("Microsoft.XMLHTTP");  
  		} 
	}
	function edit(id){ 
		var time =new Date();
		var retVal = showModalDialog ("<%=webContext %>/order/orderEdit.jsp?time="+time,"","location:No;status:No;help:No;dialogWidth:400px;dialogHeight:150px;resizable:NO;scroll:NO;");
		if(retVal!=null){
			createXMLHttpRequest();
   			var url="<s:url action='editOrder'/>?id="+id+"&u9id="+retVal[0];
   			req.open("POST", encodeURI(url), true);
   			req.setRequestHeader( "Content-Type" , "application/x-www-form-urlencoded" ) ; 
   			req.onreadystatechange=callBack;   
   			req.send(null);
		}
	}
	function callBack(){
	    if(req.readyState == 4){   
	        if(req.status == 200 || req.status == 0){   
				var message = req.responseText;
				if(message == "true")
				{
					alert("更新成功！");
				}else if(message == "hasNoOrder"){
					alert("不存在该订单！");	
				}else{
					alert("更新失败！");
				}
				reload();
	        } else {   
	            alert("xmlHttp 请求失败，错误码 " + req.status);   
	        }   
	    }   
	}
	function reload()
	{
		try
		{
			window.location.reload();
		}
		catch(e)
		{
		}
	}
</script>
<body>
	<script type="text/javascript" src="<%=webContext %>/js/datepicker/WdatePicker.js"></script>
	<s:form action="listOrdersPages" method="post" theme="simple">
		<table width="40%">
			<tr>
				<td align="right" style="font-weight:bolder">淘宝订单ID:</td>
				<td><s:textfield name="tmallID" /></td>
				<td align="right" style="font-weight:bolder">U9订单ID:</td>
				<td><s:textfield name="u9ID" /></td>
			</tr>
			<tr>
				<td align="right" style="font-weight:bolder">同步状态:</td>
				<td><s:select name="synStatus" list="#{1:'已同步',0:'未同步',2:'手工同步'}" headerKey="-1" headerValue="--请选择--"/></td>
				<td></td>
				<td></td>
			</tr>
			<tr>
				<td align="right" style="font-weight:bolder">天猫创建时间 从:</td>
				<td><s:textfield id="ltCreateDate" name="ltCreateDate" onclick="WdatePicker()"/></td>
				<td align="right" style="font-weight:bolder">至:</td>
				<td><s:textfield id="rtCreateDate" name="rtCreateDate" onclick="WdatePicker()"/></td>
			</tr>
			<tr>
				<td>&nbsp;</td>
				<td>&nbsp;</td>
				<td>&nbsp;</td>
				<td align="right" style="font-weight:bolder"><s:submit value="查询"></s:submit></td>
			</tr>
		</table>
	</s:form>  
	<br>共 <s:property value="total"/>页  第 <s:property value="pageNo"/>页<br><br>
	<p:pages pageNo="pageNo" total="total" includes="tmallID,u9ID,synStatus,ltCreateDate,rtCreateDate" styleClass="page" theme="number"/>
	<br>
	<table  border="1" align="center" width="95%">
		<tr align="center" style="font-weight:bolder">
			<td width="40px" style="background: lightgray;">序号</td>
			<td width="180px" style="background: lightgray;">淘宝订单ID</td>
			<td width="180px" style="background: lightgray;">U9订单ID</td>
			<td width="80px" style="background: lightgray;">同步状态</td>
			<td width="180px" style="background: lightgray;">同步到U9时间</td>
			<td width="100px" style="background: lightgray;">同步人</td>
			<td width="180px" style="background: lightgray;">天猫订单创建时间</td>
			<td width="80px" style="background: lightgray;">操作</td>
		</tr>
		<s:iterator value="orderList" id="ord" status="index" >
			<s:url var="url" action="selectOrder">   
          		<s:param name="id" value="#ord.getId()"/>   
      		</s:url> 
		
			<tr>
				<td><s:property value="#index.index+1"/></td>   
		    	<td><s:property value="tmallID" /></td>
		    	<td><s:property value="u9ID" />&nbsp;</td>     
		    	<td><s:if test="synStatus==1">已同步</s:if><s:elseif test="synStatus==2">手工同步</s:elseif><s:else>未同步</s:else></td>
		    	<td><s:date name="synDate" format="yyyy-MM-dd HH:mm"/>&nbsp;</td>  
		    	<td><s:property value="synUserName" />&nbsp;</td> 
		    	<td><s:date name="createDate" format="yyyy-MM-dd HH:mm"/></td>
		    	<td align="center">
		    		<s:if test="synStatus==1||synStatus==2">
		    			<s:a href="%{url}"  target="_blank">查看</s:a>
		    		</s:if>
		    		<s:else>
		    			<s:a href="%{url}"  target="_blank">同步</s:a>&nbsp;
		    			<a href="javascript:edit('<s:property value="id" />')" >手工</a>
		    		</s:else>
		    	</td>
		    </tr> 
		</s:iterator>  
	</table>
	
</body>
</html>